import java.util.ArrayList;

public class Parser {
	
	private ArrayList<String> missing = new ArrayList<String>();
	private Measurement measurement;
	
	public Measurement getMeasurement() {
		return measurement;
	}
	
	public ArrayList<String> getMissing() {
		return missing;
	}

	public void parseLine(String inputLine) {
		if(inputLine.startsWith("<?xml version=\"1.0\"?>")) {
			
		}
		else if(inputLine.startsWith("<WEATHERDATA>") || inputLine.startsWith("</WEATHERDATA>")) {
			
		}
		else if(inputLine.startsWith("<MEASUREMENT>")) {
			measurement = new Measurement();	
			missing.clear();
		}
		else if (!inputLine.startsWith("</MEASUREMENT>")){
          String[] split = null;
          split = inputLine.split(">|<");
          
          if(split[2] != null && !split[2].equals("")) {
		      switch(split[1]) {
				case "STN":
					measurement.setStn(Integer.parseInt(split[2]));
					break;
				case "DATE":
					String[] d = split[2].split("-");
					int date = Integer.parseInt(d[0] + d[1] + d[2]);
					measurement.setDate(date);
					break;
				case "TIME":
					String[] t = split[2].split(":");
					int time = Integer.parseInt(t[0] + t[1] + t[2]);
					measurement.setTime(time);
					break;
				case "TEMP":
					measurement.setTemp(Float.parseFloat(split[2]));
					break;
				case "DEWP":
					measurement.setDewp(Float.parseFloat(split[2]));
					break;
				case "STP":
					measurement.setStp(Float.parseFloat(split[2]));
					break;
				case "SLP":
					measurement.setSlp(Float.parseFloat(split[2]));
					break;
				case "VISIB":
					measurement.setVisib(Float.parseFloat(split[2]));
					break;
				case "WDSP":
					measurement.setWdsp(Float.parseFloat(split[2]));
					break;
				case "PRCP":
					measurement.setPrcp(Float.parseFloat(split[2]));
					break;
				case "SNDP":
					measurement.setSndp(Float.parseFloat(split[2]));
					break;
				case "FRSHTT":
					measurement.setFrshtt(Integer.parseInt(split[2]));
					break;
				case "CLDC":
					measurement.setCldc(Float.parseFloat(split[2]));
					break;
				case "WNDDIR":
					measurement.setWnddir(Integer.parseInt(split[2]));
					break;
				default: 
					break;
		
			}
          }
          else {
        	  missing.add(split[1]);
          }

          }
		}
	}

